package cn.ihelloworld.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

@Entity
@GenericGenerator(name="idGenerator", strategy="uuid")
public class Article implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1284180215362471959L;
	
	private String id;
	private String title;
	private String author;
	private Integer readCount;
	private Integer commentCount;
	private String fromSite;
	private String summary;
	private String tag;
	private String content;
	private String css;
	private Integer audit;
	private Date createDate;
	private Catagory catagory;
//	private List<Commentary> comments;
	
	private String catagoryId;
	private String catagoryCode;
	private String catagoryName;
	
	public Article(){
		
	}
	public Article(String id,String title){
		this.id=id;
		this.title=title;
	}
	public Article(String id,String title,String summary){
		this.id=id;
		this.title=title;
		this.summary=summary;
	}
	public Article(String id,String title,String summary,String catagoryCode){
		this.id=id;
		this.title=title;
		this.summary=summary;
		Catagory catagory=new Catagory();
		catagory.setCode(catagoryCode);
		this.catagory=catagory;
	}
	@Id
	@GeneratedValue(generator="idGenerator")
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	@Column(name="read_count")
	public Integer getReadCount() {
		return readCount;
	}
	public void setReadCount(Integer readCount) {
		this.readCount = readCount;
	}
	@Column(name="comment_count")
	public Integer getCommentCount() {
		return commentCount;
	}
	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}
	@Column(name="from_site")
	public String getFromSite() {
		return fromSite;
	}
	public void setFromSite(String fromSite) {
		this.fromSite = fromSite;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public String getTag() {
		return tag;
	}
	public void setTag(String tag) {
		this.tag = tag;
	}
	@Column(columnDefinition="LONGTEXT")
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	@Column(columnDefinition="text")
	public String getCss() {
		return css;
	}
	public void setCss(String css) {
		this.css = css;
	}
	public Integer getAudit() {
		return audit;
	}
	public void setAudit(Integer audit) {
		this.audit = audit;
	}
	@Column(name="create_date",columnDefinition="datetime")
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
//	@ManyToOne(targetEntity=Catagory.class,fetch=FetchType.EAGER)
	@ManyToOne(cascade=CascadeType.REFRESH)
    @JoinColumn(name="catagory_id") 
	public Catagory getCatagory() {
		return catagory;
	}
	public void setCatagory(Catagory catagory) {
		this.catagory = catagory;
	}
	@Transient
	public String getCatagoryId() {
		return catagoryId;
	}
	public void setCatagoryId(String catagoryId) {
		this.catagoryId = catagoryId;
	}
	@Transient
	public String getCatagoryCode() {
		return catagoryCode;
	}
	public void setCatagoryCode(String catagoryCode) {
		this.catagoryCode = catagoryCode;
	}
	@Transient
	public String getCatagoryName() {
		return catagoryName;
	}
	public void setCatagoryName(String catagoryName) {
		this.catagoryName = catagoryName;
	}

}
